<?php
/*
 * @@Copyright (C), 2021-2022: 恒盛时代
 * @Author: zhouzhou
 * @Date: 2021/12/3
 * @Description:添加我的方式隐私
 */

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class ImUserWay extends BaseModel
{
    protected $table = 'im_user_way';
    public $fillable = ['user_id'];
    protected $hidden = ['created_at','updated_at'];

    /**
     * @desc 设置我的隐私添加方式
     * @param array $input 传过来数组对象
     * @param int $userId 用户id
     * @return array|int[]
     * @author zhouzhou
     * @time 2021/12/3 14:58
     */
    public function setWay($input,  $userId)
    {
        $type = $input['type'];
        $value = $input['value'];
        $userWay = $this->where('user_id', $userId)->first();

        switch($type)
        {
            case ($type == 1):  // 加我为好友时需要验证：默认1打开需要，0不需要
                $userWay->friend_check = $value;
                break;
            case ($type == 2):  // 邀请我进群需要验证：默认1打开需要，0不需要
                $userWay->group_check = $value;
                break;
            case ($type == 3):  // 找到我的方式：手机号，默认1打开，0关闭
                $userWay->phone_way = $value;
                break;
            case ($type == 4):  // 找到我的方式：im微信号，默认1打开，0关闭
                $userWay->wx_way = $value;
                break;
            case ($type == 5):  // 找到我的方式：昵称，默认1打开，0关闭
                $userWay->name_way = $value;
                break;
            case ($type == 6):  // 添加我的方式：群聊，默认1打开，0关闭
                $userWay->group_way = $value;
                break;
            case ($type == 7):  // 添加我的方式：我的二维码，默认1打开，0关闭
                $userWay->code_way = $value;
                break;
            case ($type == 8):  // 添加我的方式：我的名片，默认1打开，0关闭
                $userWay->card_way = $value;
                break;
            case ($type == 9):  // 允许朋友查看朋友圈范围默认1全部，2最近半年，3最近一个月4最近三天
                $userWay->firend_circle = $value;
                break;
            case ($type == 10):  // 允许陌生人查看十条朋友圈，默认0不允许，1允许
                $userWay->stranger_circle = $value;
                break;
            default :
                break;
        }

        if($userWay->save() == FALSE)
        {
            return ['code' => 1, 'msg' => '设置失败'];
        }

        return ['code' => 0, 'id' => $this->id, 'msg' => '设置成功'];
    }

    /**
     * 通过uid获取查询朋友圈权限
     * @param array $fileIds
     * @return array
     */
    public function getWayCircleByuid($uids)
    {
        if (empty($uids))
        {
            return [];
        }

        $query = $this->whereIn('user_id', $uids);
        $list = $query->select('id','user_id','firend_circle')
            ->get()->toArray();
        if ($list)
        {
            return $list;
        }

        return [];
    }




}
